﻿using Bmz.MongoDb.Entities;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Bmz.MongoDb.Repositories
{
    public interface IRepository<T, TKey>
        where T : IEntity<TKey>
    {
        IMongoCollection<T> Collection { get; }

        T GetById(TKey id);

        IQueryable<T> GetAll();

        IEnumerable<T> GetList(FilterDefinition<T> filter);

        IEnumerable<T> GetList(Expression<Func<T, bool>> predicate);

        ListResp<T> GetPage(int start, int rows, FilterDefinition<T> filter, SortDefinition<T> sort = null, bool hasTotal = false);

        ListResp<T> GetPage(int start, int rows, Expression<Func<T, bool>> predicate, Expression<Func<T, object>> sort = null, bool hasTotal = false);

        void Add(T entity);

        void Add(IEnumerable<T> entities);

        UpdateResult Update(FilterDefinition<T> filter, UpdateDefinition<T> update);

        UpdateResult Save(FilterDefinition<T> filter, UpdateDefinition<T> update);

        DeleteResult Delete(TKey id);

        DeleteResult Delete(T entity);

        DeleteResult Delete(FilterDefinition<T> filter);

        DeleteResult Delete(Expression<Func<T, bool>> predicate);

        DeleteResult DeleteAll();

        long Count();

        long Count(FilterDefinition<T> filter);

        long Count(Expression<Func<T, bool>> predicate);

        bool Exists(Expression<Func<T, bool>> predicate);
    }

    public interface IRepository<T> : IRepository<T, ObjectId>
        where T : IEntity { }
}
